package Frame.screen;

import FCRendering.FCRMaster;
import FCRendering.ImageUtil;
import utils.FCUIConfig;

import java.awt.*;
import java.awt.event.MouseEvent;

import static FCRendering.FCRMaster.*;

//游戏开始界面， 主菜单界面
public class DefaultHomeScreen extends IScreen {
    @Override
    public void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster) {
        // 渲染vword
        if (fcv.getFrames() < 300) {
            g.drawImage(ImageUtil.getImage("vword"), 0, 0, fcrMaster.getWidth(), fcrMaster.getHeight(), this);
            // 渲染DATA EAST
        }
        if (fcv.getFrames() >= 300 && fcv.getFrames() < 550) {
            g.drawImage(ImageUtil.getImage("de"), 0, 0, fcrMaster.getWidth(), fcrMaster.getHeight(), this);
        }
        if (fcv.getFrames() > 960) {
            g.drawImage(ImageUtil.getImage("mm"), 0, 0, fcrMaster.getWidth(), fcrMaster.getHeight(), this);
            g.setFont(fcrMaster.getFont());
            g.setColor(Color.white);
            // 鼠标进入选项后的样子
            if (fcv.getEnterBu() == 1 && fcv.getClickBu() == 0)
                g.drawImage(ImageUtil.getImage("oneplayer2"), (fcrMaster.getWidth() - fcv.getPlayerw()) / 2, fcrMaster.getHeight() / 2 + fcv.getPlayerh(),fcv.getPlayerw(), fcv.getPlayerh(), this);
            else
            	g.drawImage(ImageUtil.getImage("oneplayer1"), (fcrMaster.getWidth() - fcv.getPlayerw()) / 2, fcrMaster.getHeight() / 2 + fcv.getPlayerh(),fcv.getPlayerw(), fcv.getPlayerh(), this);
            if (fcv.getEnterBu() == 2 && fcv.getClickBu() == 0)
                g.drawImage(ImageUtil.getImage("twoplayer2"), (fcrMaster.getWidth() - fcv.getPlayerw()) / 2,fcrMaster.getHeight() / 2 + fcv.getPlayerh() * 3, fcv.getPlayerw(), fcv.getPlayerh(), this);
            else
            	g.drawImage(ImageUtil.getImage("twoplayer1"), (fcrMaster.getWidth() - fcv.getPlayerw()) / 2,fcrMaster.getHeight() / 2 + fcv.getPlayerh() * 3, fcv.getPlayerw(), fcv.getPlayerh(), this);
            if (fcv.getEnterBu() == 3 && fcv.getClickBu() == 0)
                g.setColor(Color.gray);
            g.drawString(fcrMaster.getVwordg(), (fcrMaster.getWidth() - g.getFontMetrics(fcrMaster.getFont()).stringWidth(fcrMaster.getVwordg())) / 2, fcrMaster.getHeight() - (int) (92 * fcv.getProportion()));
            // info窗口
            if (fcv.getClickBu() == 4) {
                g.drawImage(ImageUtil.getImage("thankwin"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                        (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 41)
                    g.drawImage(ImageUtil.getImage("returnmaster"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 42)
                    g.drawImage(ImageUtil.getImage("exitgame"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
            }
            // 联机窗口
            if (fcv.getClickBu() == 2) {
                g.drawImage(ImageUtil.getImage("fondorcreate"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                        (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 6)
                    g.drawImage(ImageUtil.getImage("returnmaster"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 7)
                    g.drawImage(ImageUtil.getImage("exitgame"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 8 || fcv.getHouseNum() == 3)
                    g.drawImage(ImageUtil.getImage("fond"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
                if (fcv.getEnterBu() == 9 || fcv.getHouseNum() == 2)
                    g.drawImage(ImageUtil.getImage("create"), (int) ((fcrMaster.getWidth() - 333 * fcv.getProportion()) / 2), fcrMaster.getHeight() / 2,
                            (int) (333 * fcv.getProportion()), (int) (203 * fcv.getProportion()), this);
            }
        }

        // 渲染ZZJB
        if (fcv.getFrames() >= 540) {
            g.drawImage(ImageUtil.getImage("ZZJB"), 0, fcv.getMMTitleCoorY(), fcrMaster.getWidth(), fcrMaster.getHeight(), this);
        }
    }

    @Override
    public void setBounds() {

    }

    @Override
    public void listen_mouse_move_game(MouseEvent g) {
        int ti = FCRMaster.fcv.getFrames();
        int clickBu = FCRMaster.fcv.getClickBu();
        int x = g.getX(), y = g.getY();
        if (ti > 960) {// 主菜单界面
            if (clickBu == 0) {
                if (FCUIConfig.getIn().checkUIClick("singlePlay", x, y)) {
                    FCRMaster.fcv.setEnterBu(1);// 进入单人游戏选项
                } else if (FCUIConfig.getIn().checkUIClick("multiPlay", x, y)) {
                    FCRMaster.fcv.setEnterBu(2);// 进入双人游戏选项
                } else if (FCUIConfig.getIn().checkUIClick("vWord", x, y)) {
                    FCRMaster.fcv.setEnterBu(3);// 进入info选项
                } else {
                    FCRMaster.fcv.setEnterBu(0);
                }
            }
            if (clickBu == 4) {
                if (FCUIConfig.getIn().checkUIClick("back", x, y)) {
                    FCRMaster.fcv.setEnterBu(41);// info返回
                } else if (FCUIConfig.getIn().checkUIClick("exit", x, y)) {
                    FCRMaster.fcv.setEnterBu(42);// 退出
                } else {
                    FCRMaster.fcv.setEnterBu(0);
                }
            } else if (clickBu == 2) {// 双人选项
                if (FCUIConfig.getIn().checkUIClick("multiPlayBack", x, y)) {
                    FCRMaster.fcv.setEnterBu(6);
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayStart", x, y)) {
                    FCRMaster.fcv.setEnterBu(7);
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayFindRoom", x, y)) {
                    FCRMaster.fcv.setEnterBu(8);
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayNewRoom", x, y)) {
                    FCRMaster.fcv.setEnterBu(9);
                } else {
                    FCRMaster.fcv.setEnterBu(0);
                }
            }
        }
    }


    @Override
    public void listen_mouse_click_game(MouseEvent g) {
        int ti = FCRMaster.fcv.getFrames();
        int x = g.getX(), y = g.getY();
        if (ti < 960 && FCRMaster.charLib.getCharacterAllNum() == FCRMaster.charLib.getCharacterNum()) {// 点击跳过游戏开头
            FCRMaster.fcv.setFrames(960);
            FCRMaster.fcv.setMMTitleCoorY(0);
        } else if (ti > 960) {// 主菜单界面
            if (FCRMaster.fcv.getClickBu() == 4) {
                if (FCUIConfig.getIn().checkUIClick("back", x, y)) {
                    FCRMaster.fcv.setClickBu(0);// info 返回
                } else if (FCUIConfig.getIn().checkUIClick("exit", x, y)) {
                    System.exit(0);// 退出
                }
            } else if (FCRMaster.fcv.getClickBu() == 2) {
                if (FCUIConfig.getIn().checkUIClick("multiPlayBack", x, y)) {
                    FCRMaster.fcv.setClickBu(0);// info 返回
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayStart", x, y)) {
                    FCRMaster.fcv.setInterfacenum(FCRMaster.fcv.getHouseNum());
                    FCRMaster.fcv.setSever((FCRMaster.fcv.getInterfacenum() == 2) ? true : false);
                    if (FCRMaster.fcv.getInterfacenum() == 2) {
                        FCRMaster.fcv.setClickBu(1);
                    } else {
                        FCRMaster.fcv.setClickBu(3);
                    }
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayFindRoom", x, y)) {
                    FCRMaster.fcv.setHouseNum(3);
                    FCRMaster.sound.setBackgroundMusic(1);
                } else if (FCUIConfig.getIn().checkUIClick("multiPlayNewRoom", x, y)) {
                    FCRMaster.fcv.setHouseNum(2);
                    FCRMaster.sound.setBackgroundMusic(1);
                }
            } else if (FCRMaster.fcv.getClickBu() == 0) {
                if (FCUIConfig.getIn().checkUIClick("singlePlay", x, y)) {
                    FCRMaster.fcv.setInterfacenum(1);
                    FCRMaster.fcv.setClickBu(1);
                    FCRMaster.sound.setBackgroundMusic(1);
                } else if (FCUIConfig.getIn().checkUIClick("multiPlay", x, y)) {
                    FCRMaster.fcv.setClickBu(2);
                } else if (FCUIConfig.getIn().checkUIClick("vWord", x, y)) {
                    FCRMaster.fcv.setClickBu(4);
                }
            }
        }
    }
}
